 #ifndef dht11_h
#define dht11_h

#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

#define DHT11LIB_VERSION "0.1.0"

#define DHTLIB_OK         0
#define DHTLIB_ERROR_CHECKSUM -1
#define DHTLIB_ERROR_TIMEOUT  -2

#define BEGIN_TIME       20  // ms
#define GO_TIME          30  // us
#define REPLY_LOW_TIME   83  // us
#define REPLY_HIGH_TIME  87  // us
#define DATA_LOW_TIME    54  // us
#define DATA_HIGH_0_TIME 24  // us
#define DATA_HIGH_1_TIME 71  // us
#define RELEASE_TIME     54  // us

#define THINK_TIME       40  // us

class DHT11
{
public:
  DHT11(uint8_t pin);

    uint8_t read(uint8_t usec=55);
  float   getHumidity();
  float   getTemperature(bool isFahrenheit=false);
  float   convertCtoK(float c);
  float   convertCtoF(float c);
  float   convertFtoC(float f);
  double  dewPoint(double celsius, double humidity);
  double  dewPointFast(double celsius, double humidity);
  float   computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);

private:
  uint8_t data[5];
  uint8_t _pin;

  void resetBuffer(uint8_t *buf, uint8_t size);
  uint8_t checksum();
};
#endif
